package laba1.task1;

/**
 *
 * @author yakimovich
 */
public class MatrixTest {

    public static void main(String[] args) {
        //working correctly
        double[][] data1 = {{0.0, 0.0}, {0.0, 1.0}};
        double[][] data2 = {{1.0, 0.0}, {1.0, 1.0}};
        test(data1, data2);

        //throws IllegalArgumentException when transpose() called:
        //it is impossible to create a Matrix based on a one-dimensional array;        
        //throws IllegalArgumentException when mult() called
        double[][] data3 = {{0.0}, {1.0}};
        double[][] data4 = {{1.0}, {2.0}};
        test(data3, data4);

        //working correctly      
        double[][] data5 = {{-5.2, 0.0}, {0.1, -1.2}};
        double[][] data6 = {{3.3, -1.9}, {1.5, 1.1}};
        test(data5, data6);

        //throws IllegalArgumentException when transpose() called:
        //it is impossible to create a Matrix based on a one-dimensional array;        
        //throws IllegalArgumentException when mult() called
        double[][] data7 = {{-0.7, 0.0, 8.8}, {0.2, -1.1, -7.5}};
        double[][] data8 = {{3.2, -1.3, 0.0}, {1.0, 1.9, 9.2}};
        test(data7, data8);

        //throws IllegalArgumentException when transpose() called:
        //it is impossible to create a Matrix based on a one-dimensional array;  
        //throws IllegalArgumentException when sum() called
        //throws IllegalArgumentException when mult() called
        double[][] data9 = {{1.0, 3.1}, {-2.6, 4.0, 3.0}};
        double[][] data10 = {{0.5}, {5.5, -6.6}};
        test(data9, data10);
    }

    /**
     * Create two Matrixes and a demonstration use of their methods
     *
     * @param data1 array to create a Matrix
     * @param data2 array to create a Matrix
     */
    private static void test(double[][] data1, double[][] data2) {
        Matrix m1 = new Matrix(data1);
        Matrix m2 = new Matrix(data2);
        try {
            System.out.println("First Matrix: ");
            m1.printMatrix();
            System.out.println("Second Matrix: ");
            m2.printMatrix();
        } catch (IllegalArgumentException e) {
            System.out.println(e);
            System.out.println();
        }
        try {
            System.out.println("Transpose of the First Matrix: ");
            m1.transpose().printMatrix();
        } catch (IllegalArgumentException e) {
            System.out.println(e);
            System.out.println();
        }
        try {
            System.out.println("Sum of the Matrixes: ");
            m1.sum(m2).printMatrix();
        } catch (IllegalArgumentException e) {
            System.out.println(e);
            System.out.println();
        }
        try {
            System.out.println("Mult of the Matrixes: ");
            m1.mult(m2).printMatrix();
        } catch (IllegalArgumentException e) {
            System.out.println(e);
        }
        System.out.println("********************************************************************");
    }
}
